﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AForge;
using AForge.Neuro;
using AForge.Neuro.Learning;
using AForge.Controls;
using AForge.Genetic;
using AForge.Math;
using AForge.Math.Random;


namespace NN
{
    class NNetwork
    {
        ActivationNetwork net;
        BackPropagationLearning bprop;
        //EvolutionaryLearning ga;
        Population p;
        public NNetwork()
        {

        }
        public void Init(int [] layers, int act)
        {
            int inputs = layers[0];
            int[] nodes= null;
            for (int i = 1; i < layers.Length; i++) 
            {
                nodes[i - 1] = layers[i];
            }
            switch (act)
            {
                case 0:  //      BipolarSigmoidFunction
                    net = new ActivationNetwork(new BipolarSigmoidFunction(), inputs, nodes); break;
                case 1:  //      SigmoidFunction
                    net = new ActivationNetwork(new SigmoidFunction(), inputs, nodes); break;
                case 2:  //      ThresholdFunction
                    net = new ActivationNetwork(new ThresholdFunction(), inputs, nodes); break;
                

            }
        }
        public void BProp(double learningRate, double momentum )
        {
            bprop = new BackPropagationLearning(net);
            bprop.LearningRate = learningRate;
            bprop.Momentum = momentum;
        }
        public double[] Compute(double[] input)
        {            
            return net.Compute(input);
        }
        public double TrainBatch(double[][] inputs, double[][] outputs)
        {
            return bprop.RunEpoch(inputs, outputs);
        }
        public double TrainSingle(double[] inputs, double[] outputs)
        {
            return bprop.Run(inputs, outputs);
        }
        /*
        public void GA(int population)
        {
            ga = new EvolutionaryLearning(net, population);
            
        }
        public void GA(int population, double crossover, double )
        {
            //ga = new EvolutionaryLearning(net, population, gene
        }
        public void Evolve()
        {
            
        }
        public void getPopulation()
        {
            
        }*/
        
    }
}
